package asu.util
{
	import flash.external.ExternalInterface;
	import flash.net.URLRequest;
	
	public class UrlUtil
	{
		public static var nocache:Boolean;
		
		public static function getContainerURL():String
		{
			if( ExternalInterface.available )
			{
				return ExternalInterface.call("window.location.href.toString");
			}
			//_root.loaderInfo.url
			return null;
		}
		
		public static function stripProtocol( url:String ):String
		{
			return url.split('://').pop();
		}
		
		public static function getDomain( url:String ):String
		{
			url = stripProtocol( url );
			return url.split('/')[0];
		}
		
		public static function getPathArray( url:String ):Array
		{
			if( !url ) return [];
			
			url = stripQuery( stripProtocol( url ) );
			var parts:Array = url.split('/');
			parts.shift();
			return parts;
		}
		
		public static function stripQuery( url:String ):String
		{
			return url.split('?')[0];
		}
		
		public static function getQuery( url:String ):String
		{
			return url.split('?')[1];
		}
		
		public static function getUrlRequest( url:String ):URLRequest
		{
			var nurl:String = (nocache) ? url+'?nocache='+StringUtil.generateRandomString( 8 ) : url;
			return new URLRequest( nurl );
		}
	}
}